package com.webflux.dmeo.streamDemo;

import lombok.Data;

import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Created by wangzhanjin on 2018/5/31.
 */
@Data
class Student {
    private String name;
    private Integer age;

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }
}

public class CollectionDemo {
    public static void main(String[] args) {
        List<Student> students = Arrays.asList(
                new Student("张三",10),
                new Student("李四",12),
                new Student("王五",20),
                new Student("赵柳",20)
        );
        //得到所有学生年龄列表
        List<Integer> ages = students.stream().map(s -> s.getAge()).collect(Collectors.toList());
        Set<Integer> agesSet = students.stream().map(s -> s.getAge()).collect(Collectors.toSet());
        System.out.println("所有学生的年龄："+ages);
        System.out.println("所有学生的年龄Set："+agesSet);
        //统计汇总信息
        IntSummaryStatistics collect = students.stream().collect(Collectors.summarizingInt(Student::getAge));
        System.out.println(collect);
    }
}
